/**
 * 功能数据表格
 */
Ext.namespace("Ext.ux.grid");

Ext.ux.grid.FuncGrid = Ext.extend(Ext.ux.grid.CrudGrid, {

	//是否启用行双击事件的事件处理函数，取值为true，为grid添加默认的行双击事件处理函数，取值为false不添加
	enabledDefaultRowDblclickEvent: false,
	initComponent: function(){
		var gridStructure = [{  
			name: 'funcId',
			hidden: true
		},{
			name: 'funcCode',  
			header: "功能编号",
			sortable: true,
			width: 50
		},{
			name: 'funcName',  
			header: "功能名称",
			sortable: true,
			width: 60
		},{
			name: 'funcTypeLabel',  
			header: "功能类型",
			width: 50
		},{
			name: 'appName',
			header: '所属应用',
			width: 50
		},{
			name: 'moduleName',
			header: '模块路径',
			width: 50
		},{
			name: 'menuNames',
			header: '关联菜单名称',
			width: 100
		},{
			name: 'funcUrl',  
			header: "功能调用入口",
			width: 100
		}];
		
		this.structure = gridStructure;
		this.defaultSortField = 'funcCode';
		this.keyField = 'funcId';
		
		this.deleteMsg = '确认要删除选中的功能吗？<br/><font color="red">注意</font>：删除功能将同时删除与功能相关的菜单、角色关联信息。';
		this.deleteMsgBoxWidth = 420;
		
		Ext.ux.grid.FuncGrid.superclass.initComponent.call(this);
		
		//如果启用了行双击事件的处理函数
		if(this.enabledDefaultRowDblclickEvent){
			this.on('rowdblclick', function(funcGrid){
				var record = funcGrid.getSelectionModel().getSelected();
				if(record != null){
					var funcId = record.get('funcId');
					this.showFuncInfo(funcId);
				}
			});
		}
		
		
		this.on('updateRecord', function(funcId){
			this.showFuncInfo(funcId);
		});
		
		this.on('deleteRecord', function(grid, funcIds){
			this.deleteFunc(funcIds);
		});
	},
	
	addFunc: function(moduleId){
		var win = new Ext.ux.org.acapp.FuncDetailWindow({id:'funcDetailWindow', title:'新增功能', moduleId:moduleId});
		win.showAddFuncWin();
	},
	
	showFuncInfo: function(funcId){
		var win = new Ext.ux.org.acapp.FuncDetailWindow({id:'funcDetailWindow', title:'修改功能', funcId:funcId});
		win.showFuncInfo();
	},
	
	deleteFunc: function(funcIds) {
		Ext.Ajax.request({
			url: 'ac-function!delete.action',
			success: function(){
				Ext.getCmp('appTree').refreshApp();
				this.store.reload();
			},
			failure: function(form, action) {
				Ext.Msg.alert('系统提示', '删除功能失败！');
			},
			method: 'POST',
			params:{
				ids: funcIds
			},
			waitMsg : '正在删除数据，稍候...',
			scope: this
		});
	}
});